﻿using System;
using System.Net;
using System.Security.Cryptography;
using System.Text;

namespace Groovy_IM.Protocols.AIM
{
    public class AIMClasses
    {
        public static byte[] encryptPW(byte[] Challenge, byte[] Password)
        {
            byte[] MD5Pass = MD5Core.GetHash(Password);

            byte[] MD5Salt = Encoding.UTF8.GetBytes("AOL Instant Messenger (SM)");

            byte[] MD5Hash = new byte[Challenge.Length + MD5Pass.Length + MD5Salt.Length];

            Buffer.BlockCopy(Challenge, 0, MD5Hash, 0, Challenge.Length);

            Buffer.BlockCopy(MD5Pass, 0, MD5Hash, Challenge.Length, MD5Pass.Length);

            Buffer.BlockCopy(MD5Salt, 0, MD5Hash, MD5Pass.Length + Challenge.Length, MD5Salt.Length);

            byte[] Hash = MD5Core.GetHash(MD5Hash);

            return Hash;
        }

        public static byte[] String_To_Bytes(string strInput)
        {
            strInput = strInput.Replace("-", "").Replace(",", "").ToLower().Replace(" ", "");

            int i = 0, x = 0;
            
            byte[] bytes = new byte[(strInput.Length) / 2];

            while (strInput.Length > i + 1)
            {
                long lngDecimal = Convert.ToInt32(strInput.Substring(i, 2), 16);

                bytes[x] = Convert.ToByte(lngDecimal);
                
                i += 2;
                
                x++;
            }
  
            return bytes;
        }

        public static string errorText(int error)
        {
            string status = "An unknown error has occured. If this persists, please upgrade to the latest version of Groovy IM.";

            switch (error)
            {
                case 1:
                    status = "The screenname or password you entered is not valid. Please re-enter and try again.";
                    break;
                case 2:
                    status = "The service is temporarily unavailable. Please try again in a few.";
                    break;
                case 4:
                    status = "The screenname or password you entered is not valid. Please re-enter and try again.";
                    break;
                case 5:
                    status = "The screenname or password you entered is not valid. Please re-enter and try again.";
                    break;
                case 6:
                    status = "Please upgrade to the latest version of Groovy IM.";
                    break;
                case 7:
                    status = "The screenname or password you entered is not valid. Please re-enter and try again.";
                    break;
                case 8:
                    status = "The screenname you entered is not valid. (Account Deleted)";
                    break;
                case 9:
                    status = "The screenname you entered is not valid. (Account Expired)";
                    break;
                case 10:
                    status = "The service is temporarily unavailable. Please try again in a few.";
                    break;
                case 11:
                    status = "The service is temporarily unavailable. Please try again in a few.";
                    break;
                case 12:
                    status = "The service is temporarily unavailable. Please try again in a few.";
                    break;
                case 13:
                    status = "The service is temporarily unavailable. Please try again in a few.";
                    break;
                case 14:
                    status = "The service is temporarily unavailable. Please try again in a few.";
                    break;
                case 15:
                    status = "The service is temporarily unavailable. Please try again in a few.";
                    break;
                case 16:
                    status = "The service is temporarily unavailable. Please try again in a few.";
                    break;
                case 17:
                    status = "The screenname you entered is not valid. (Account Suspended)";
                    break;
                case 18:
                    status = "The service is temporarily unavailable. Please try again in a few.";
                    break;
                case 19:
                    status = "The service is temporarily unavailable. Please try again in a few.";
                    break;
                case 20:
                    status = "The service is temporarily unavailable. Please try again in a few.";
                    break;
                case 21:
                    status = "The service is temporarily unavailable. Please try again in a few.";
                    break;
                case 22:
                    status = "Your IP has reached the maximum amount of users at a time.";
                    break;
                case 23:
                    status = "Your IP has reached the maximum amount of users at a time.";
                    break;
                case 24:
                    status = "You are attempting to sign on again too soon. Please try again later.";
                    break;
                case 25:
                    status = "You are too heavily warned, and cannot sign on currently.";
                    break;
                case 26:
                    status = "The service is temporarily unavailable. Please try again in a few.";
                    break;
                case 27:
                    status = "Please upgrade to the latest version of Groovy IM.";
                    break;
                case 28:
                    status = "Please upgrade to the latest version of Groovy IM.";
                    break;
                case 29:
                    status = "You are attempting to sign on again too soon. Please try again later.";
                    break;
                case 30:
                    status = "The service is temporarily unavailable. Please try again in a few.";
                    break;
                case 32:
                    status = "The service is temporarily unavailable. Please try again in a few.";
                    break;
                case 34:
                    status = "The screenname you entered is not valid. (Account Suspended)";
                    break;
            }
            return status;
        }
    }
}